/*
 * This file is part of Jeve.

    Jeve is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    Jeve is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    Copyright 2007 Jochen Bedersdorfer (beders@yahoo.com)
 *
 */
package de.monoid.eve;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * User ID is as unique identifier for the eve servers
 * @author beders
 */
public class UserID {

    private String id;

    /**
     * Create an UserID object
     * @param anId the id
     */
    public UserID(String anId) {
      id = anId;
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final UserID other = (UserID) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + this.id != null ? this.id.hashCode() : 0;
        return hash;
    }

    /**
     * Add the user id info to the URL query
     * @param requestData the buffer to append to
     */
    void encode(StringBuilder requestData) {
        try {
            requestData.append("userid").append('=').append(java.net.URLEncoder.encode(id, "UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger("global").log(Level.SEVERE, null, ex);
        }
    }
    
}
